/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sorting;

/**
 *
 * @author Akram
 */
public final class BubbleSort<T extends Comparable> extends Sort<T> {

    public BubbleSort(T[] array, Class<T> classType) {
        super(array, classType);
    }

    /**
     * Sort using bubble sort algorithm
     */
    @Override
    public void sort() {
        boolean switched = true;
        for (int i = 0; i < array.length - 1 && switched; i++) {
            switched = false;
            for (int j = 0; j < array.length - i - 1; j++) {
                if (array[j].compareTo(array[j + 1]) > 0) {
                    T tmp = array[j + 1];
                    array[j + 1] = array[j];
                    array[j] = tmp;
                    switched = true;
                }
            }
        }
    }
}
